<!-- 高通量计算 -->
<template>
  <!-- 顶部搜索区 -->
  <div class="main-app" v-loading="loading">
    <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-top: 5px; margin-bottom: 15px;">
      <el-breadcrumb-item :to="{path:'/'}">{{$t('common.nav.home')}}</el-breadcrumb-item>
      <el-breadcrumb-item>{{$t('common.nav.highThroughputComputing')}}</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <el-form :inline="true" :model="searchParam" class="form-inline" style="text-align: center;">
        <el-form-item :label="$t('common.label.elementOrFormula')+':'">
          <el-input v-model="searchParam.elements" style="width: 120vh;" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="search">{{$t('common.button.search')}}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-refresh-right" @click="reset">{{$t('common.button.reset')}}</el-button>
        </el-form-item>
      </el-form>
      <!-- 元素周期表键盘 -->
      <el-collapse v-model="activeNames">
        <el-collapse-item :title="$t('common.label.elementKeyboard')" name="elementkeyboard">
          <elements-periodic-table @click="onElementsItem" multiple elementsList></elements-periodic-table>
        </el-collapse-item>
      </el-collapse>
    </el-card>
    <!-- 数据列表区 -->
    <div class="show-result">
      <div class="table">
        <el-table id="table" ref="multipleTable" tooltip-effect="dark" stripe style="width: 100%" :data="tableData" @selection-change="handleSelectionChange">
          <el-table-column prop="material_id" :label="$t('common.label.material_id')" align="center"/>
          <el-table-column prop="composition" :label="$t('common.label.composition')" align="center"/>
          <el-table-column prop="formula_pretty" :label="$t('common.label.formula_pretty')" align="center"/>
          <el-table-column prop="chemsys" :label="$t('common.label.chemsys')" align="center"/>
          <el-table-column prop="nsites" :label="$t('common.label.nsites')" align="center"/>
          <el-table-column prop="nelements" :label="$t('common.label.nelements')" align="center"/>
          <el-table-column prop="created_at" :label="$t('common.label.created_at')" width="240" align="center">
            <template slot-scope="scope">
              {{ scope.row.created_at | parseDate }}
            </template>
          </el-table-column>
          <el-table-column fixed="right" :label="$t('common.label.operate')" align="center" width="200">
            <template slot-scope="scope">
              <el-button-group>
                <el-button size="mini" type="primary" @click="operation($t('common.button.select'), scope.row)">{{$t('common.button.select')}}</el-button>
              </el-button-group>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 列表底部分页按钮 -->
      <div class="page">
        <el-pagination background layout="total, prev, pager, next, sizes"
          :total="total"
          :current-page.sync="currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import ElementsPeriodicTable from "../../components/ElementsPeriodicTable/elementsPeriodicTable.vue"
import { pageMixin } from "../../mixins/index";
import {
  MaterialList
} from "../../api/material.js";
import Qs from "qs";
export default {
  // 页面公共变量
  data() {
    return {
      // 搜索条件参数
      searchParam: {
        elements: "",
      },
      selectList:[],                    // 已选择的元素
      dialogVisible: false,             // 是否隐藏提示框
      activeNames: ""                   // 当前选中的折叠面板 elementkeyboard
    };
  },
  // 页面创建完成事件
  async created() {
    await this.init();
  },
  // 组件
  components:{
    ElementsPeriodicTable
  },
  // 数据过滤器
  filters: {
    // 转换日期显示格式
    parseDate(value) {
      if (value.indexOf(".")>-1) {
        return value.replace("T", " ").substring(0, value.indexOf("."));
      } else {
        return value.replace("T", " ");
      }
    },
  },
  // 表格分页属性配置
  mixins: [pageMixin],
  // 页面相关方法
  methods: {
    // 初始化加载事件
    async init() {
      this.activeNames = "";      // 自动关闭元素周期表输入键盘
      this.tableData = [];        // 重置表格数据源
      this.loading = true;        // 启动加载框

      // 获取数据
      const { data, count } = await MaterialList({
        page: this.currentPage,
        limit: this.pageSize,
        elements: this.searchParam.elements
      });

      this.tableData = data;      // 设置表格数据源
      this.total = count;         // 设置表格总数据量
      this.loading = false;       // 关闭加载框
    },
    // 表格重置事件
    async reset() {
      this.searchParam = {
        elements: ""
      };
      this.selectList = [];
      await this.init();
    },
    // 操作功能按钮点击事件
    operation(value, row) {
      switch (value) {
        // 选择
        case this.$t('common.button.select'):
          this.$router.push(`/high_throughput_computing/detail/${row.id}`);
          break;
      }
    },
    // 元素周期表键盘点击事件
    onElementsItem(list) {
      this.selectList.push(list);
      //console.log('选中的元素', this.selectList.join(','));
      this.searchParam.elements = this.selectList.join('-');
    },
  },
};
</script>

<style lang="scss" scoped>
// 顶部按钮绝对定位
.formbtn { text-align: right; }
// 数据表格区样式
.show-result { margin-top: 1%; }
/* 操作项开关样式 */
::v-deep .switch .el-switch__label { position: absolute; display: none; color: #fff; }
/* 打开时文字位置设置 */
::v-deep .switch .el-switch__label--right { z-index: 1; right: 5px; }
/* 关闭时文字位置设置 */
::v-deep .switch .el-switch__label--left { z-index: 1; left: 8px; }
/* 显示文字 */
::v-deep .switch .el-switch__label.is-active { display: block; }
::v-deep .switch.el-switch .el-switch__core,
::v-deep .el-switch .el-switch__label { width: 60px !important; }
/* 表格隔行换色样式 */
::v-deep .el-table--striped .el-table__body tr.el-table__row--striped td { background-color: #F2F2F2; }
/* 表格数据行高 */
::v-deep .el-table td { padding: 8px 0px; }
/* 表头背景色样式 */
::v-deep .el-table th{ background-color: #DBEDEF !important; }
/* 表头数据行内线样式 */
::v-deep .el-table td,.building-top .el-table th.is-leaf { border-bottom: 0px; }
/* 自定义提示框样式 */
.dialog_diy {
  ::v-deep .el-dialog__wrapper {
    .el-dialog {
      .el-dialog__body { padding: 0px; }
      .el-dialog__header { padding: 0px; }
      .el-dialog__headerbtn { top: 5px; right: 5px; padding-top: 10px; }
      .el-dialog__headerbtn .el-dialog__close { color: #fff; height: 30px; width: 35px; }
      .el-dialog__headerbtn .el-dialog__close:hover { color: gray; }
    }
  }
}
</style>
